package com.baiyun.function;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import oracle.jdbc.OracleTypes;

import com.baiyun.tools.ConnDB;

public class Test {
	
	private String name;
	
	private void hh(){
		name = "";
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {

		test1();
	}

	public static void test() {
		try {

			Connection conn = ConnDB.getConnection();
			CallableStatement cs = conn
					.prepareCall("{?=call fun_getGrade(?)}");
			cs.setString(2, "001101");
			// 注册oracle输出参数的类型
			cs.registerOutParameter(1, OracleTypes.NUMBER);
			cs.execute();
			int ysal = cs.getInt(1);
			System.out.println(ysal);
			cs.close();
			conn.close();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
		}
	}

	public static void test1() {
		try {

			Connection ct = ConnDB.getConnection();
			// 3.创建PreparedStatement
			PreparedStatement ps = ct
					.prepareStatement("select fun_getGrade('001101') grade from dual");
			// 4.执行
			ResultSet rs = ps.executeQuery();
			if (rs.next()) {
				int grade = rs.getInt("grade");
				System.out.println(grade);
			}
			// 5、关闭
			rs.close();
			ps.close();
			ct.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public static void test2() {
		try {

			Connection conn = ConnDB.getConnection();
			CallableStatement cs = conn
					.prepareCall("{?=call test_pkg.delete_test(?)}");
			cs.setInt(2, 201703);
			// 注册oracle输出参数的类型
			cs.registerOutParameter(1, OracleTypes.NUMBER);
			cs.execute();
			int ysal = cs.getInt(1);
			System.out.println(ysal);
			cs.close();
			conn.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
